
import { Button, Form, Input, message, PageHeader } from 'antd';
import Layout from '../core/Layout'
// import { LeftOutlined } from '@ant-design/icons'
// import { Link } from 'react-router-dom'
import axios from 'axios';
import { API } from '../../config';
import { isAuth } from '../../helpers/auth';

function AddCategory() {
  const { token, user:{ _id }} = isAuth()
  const handelFinish = (value) =>{
    if(value.name){
      axios.post(`${API}/category/create/${ _id }`, value, {
        headers: { Authorization: `Bearer ${token}`}
      }).then(res =>{
        message.success(`${res.data.name} 添加成功！`)
      })
    }
  }
  return (
    <Layout title='添加分类' subTitle='let us go'>
      <Form onFinish={handelFinish}>
        <Form.Item label="分类名称" name="name">
          <Input />
        </Form.Item>
        <Form.Item>
          <Button type="primary" htmlType="submit">添加</Button>
        </Form.Item>
        <PageHeader onBack={() =>window.history.back() } subTitle="返回 dashboard"/>
        {/* <Form.Item>
          <Button type="text">
            <Link to='/admin/dashboard'><LeftOutlined />返回 dashboard</Link>
          </Button>
        </Form.Item> */}
      </Form>
      
    </Layout>
  )
}

export default AddCategory
